<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>档案检索申请</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <jsp:include page="/inc/head.jsp" flush="true" />
    <link href="${basePath}/js/activiti/qtip/jquery.qtip.min.css" type="text/css" rel="stylesheet" />
    <link href="${basePath}/js/activiti/jquery-ui-1.9.2.custom.css" type="text/css" rel="stylesheet" />
    <link href="${basePath}/js/activiti/style-ui.css" type="text/css" rel="stylesheet" />
    <jsp:include page="/inc/footer.jsp" flush="true" />
    <!-- picker -->
    <script src="${basePath}/js/My97DatePicker/WdatePicker.js"></script>
    <script src="${basePath}/js/activiti/qtip/jquery.qtip.pack.js" type="text/javascript"></script>
    <script src="${basePath}/js/activiti/jquery.outerhtml.js" type="text/javascript"></script>
    <script src="${basePath}/js/activiti/jquery-ui-1.9.2.min.js" type="text/javascript"></script>
    <script src="${basePath }/js/module/activiti/workflow.js"></script>
    <script src="${basePath }/js/tip.js"></script>
    <style type="text/css">
        /****************** 审核的样式 *************/

        #searchAuditModal table {
            font-size: 14px;
        }

        #searchAuditModal td {
            padding-left: 20px;
            height: 30px;
            width: 50%;
        }

        .firstTD {
            color: #AAAAAA;
        }

        #searchAuditModal tr {
            margin-top: 60px;
        }

        #auditUserView {
            border: 1px solid #AAAAAA;
            border-radius: 3px;
            height: 60px;
            width: 250px;
        }

        /****************** 审核的样式 *************/

        /****************** 调整申请的样式 **************/
        #modifyApply tr {
            width: 100%
        }

        .content {
            padding-left: 20px;
        }

        #modifyApply select {
            width: 140px;
        }

        #modifyApply input {
            border: 1px solid #AAAAAA;
            width: 140px;
            border-radius: 3px;
            /*height: 28px;*/
        }
        #modifyApply input[type=radio] {
            height:auto;
        }
        #modifyApply form {
            padding-left: 0;
        }
        #modifyApply form label {
            width:122px;
            text-align:right;
        }
        #modifyApply form label.radio-inline {

            text-align:left;
        }
        #modifyApply  bg-info
        {
           background-color: #fff;
         }

        /******************调整申请的样式*************/
        .rejectReason {
            height: 40px;
            width: 85%;
            background: yellow;
            margin-left: 20px;
            border: 1px solid cornflowerblue;
            border-radius: 3px;
        }

        td {
            font-size: 13px;
            height: 40px;
        }

        .content #rowToolBar .box-info {
            margin-bottom: 0;
            border-top: 0;
            box-shadow:none;
        }

        .content #rowToolBar .box-info .box-body {
            padding: 0 0 10px 0;

        }
        .content #borAuditDiv .bootstrap-table .fixed-table-toolbar .icon-refresh {
            padding: 3px 0;
        }
        .content #borAuditDiv {
            position: relative;
            top:-55px;
        }
        .content #rowToolBar .form-horizontal .btn-group {
            z-index: 99;
        }
        .pagination ul > .active > a {
            background-color: rgb(51, 122, 183);
            color:#fff;
        }

    </style>
</head>

<body class="hold-transition skin-blue sidebar-mini" style="overflow:hidden;">
    <!-- Main content -->
    <section class="content">
        <!-- /rowToolBar -->
        <div id="rowToolBar" class="row" style="height: 100%;">
            <div class="col-xs-12">
                <div class="box box-info">
                    <form class="form-horizontal">
                        <!-- /.box-header -->
                        <div class="box-body btn-group">
                            <shiro:hasPermission name="cms:searchmanage:searchAudit">
                                <button id="btn_myAudit" type="button" class="btn btn-default"
                                    onclick="myAuditAction()">
                                    <span class="glyphicon glyphicon-paste" aria-hidden="true"></span>我的待办流程
                                </button>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="cms:searchmanage:searchList">
                                <button id="btn_myAudit" type="button" class="btn btn-default"
                                    onclick="allSearchListAction()">
                                    <span class="glyphicon glyphicon-paste" aria-hidden="true"></span>检索登记列表
                                </button>
                            </shiro:hasPermission>
                        </div>
                        <!-- /.box-body -->
                    </form>
                    <!-- /.form -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col-xs-12 -->
        </div>
        <div class="" id="borAuditDiv">
        <%--<div class="box-body table-responsive no-padding" id="borAuditDiv">--%>
            <!-- 当前的代办table -->
            <table id="borAuditTable">
            </table>
        </div>

        <%--检索申请资料模态框--%>
        <div id="searchAuditModal" class="modal fade bs-example-modal-lg addUpdateInfo" role="dialog"
            aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog " role="document">
                <div class="modal-content" style="width: 350px;">
                    <div class="modal-header" style="background: #455EC5;">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">待办审核【检索审核】</h4>
                    </div>
                    <form id="searchApplyForm" class="form-horizontal form-bordered form-row-strippe"
                        data-toggle="validator" enctype="multipart/form-data">
                        <table style="width: 100%">
                            <tr>
                                <td>借阅人：</td>
                                <td id="borUserName" class="firstTD"> </td>
                            </tr>
                            <tr>
                                <td>检索人部门</td>
                                <td id="borDeptName" class="firstTD"></td>
                            </tr>
                            <tr id="borAttestUrlTr">
                                <td>借&nbsp;阅&nbsp;人&nbsp;证&nbsp;明：</td>
                                <td class="firstTD">
                                    <input type="hidden" id="urlHidden" value="">
                                    <input type="button" id="borAttestUrl" value="查看证明">
                                </td>
                            </tr>
                            <tr>
                                <td>检索截止时间</td>
                                <td id="planReturnTime" class="firstTD"></td>
                            </tr>
                            <tr>
                                <td>检索内容</td>
                                <td id="auditDetail" class="firstTD"></td>
                            </tr>
                            <tr>
                                <td>检索原因</td>
                                <td id="auditReason" class="firstTD"></td>
                            </tr>
                            <tr>
                                <td>审&nbsp;&nbsp;&nbsp;批&nbsp;&nbsp;意&nbsp;&nbsp;见：</td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <textarea class="bigLongText" id="auditUserView" name="auditUserView"
                                        maxlength="20">
                                </textarea>
                                </td>
                            </tr>
                            <tr id="auditPointUserDiv" style="display: none">
                                <td class="content">
                                    指定下级领导审批:
                                </td>
                                <td colspan="5" class="form-group">
                                    <select id="auditUserTable" data-delegateUser="" style="width:80%">
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </form>
                    <div class="modal-footer bg-info">
                        <input type="hidden" id="borId" value="">
                        <input type="hidden" id="taskId" value="">
                        <input type="hidden" id="taskType" value="">
                        <button type="button" class="btn blue" id="passSumbit"
                            onclick="borAuditResult(1,this);">通过</button>
                        <button type="button" class="btn blue" id="rejectSumbit"
                            onclick="borAuditResult(0,this);">驳回</button>
                        <button type="button" class="btn green" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <%--重新申请的流程--%>
        <div id="modifyApply" class="modal fade bs-example-modal-lg addUpdateInfo" role="dialog"
            aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog " role="document">
                <div class="modal-content" style="width: 600px;">
                    <div class="modal-header" >
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="againAuditLabel">流程办理[调整申请]</h4>
                    </div>


                    <div class="modal-body" style="height: 473px;">

                        <form class="form radio" role="form" style="padding-left:10px;">
                            <div class="form-group">
                                <label>领&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;导：</label>
                                <span id="rejectReason" ></span>
                            </div>
                            <div class="form-group">
                                <label class="control-label">申&nbsp;&nbsp;请&nbsp;&nbsp;类&nbsp;&nbsp;别：</label>
                                <label class="radio-inline">
                                    <input type="radio" name="adStatus" id="adStatus_1" value="1" style="width:auto;"> 调整申请
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="adStatus" id="adStatus_0" value="0" style="width:auto;"> 取消申请
                                </label>
                            </div>


                            <!-- 具有组织部门的申请列表 -->
                            <div style="display: none;" id="modifyTable">
                                <div class="form-group">
                                    <label  class="control-label">申请检索部门：</label>
                                    <select id="borDeptTwo" name="borDept" class="form-control" style="width: 25%;display: inline-block">
                                    </select>
                                    <input  class="form-control" type='text' id="auditDeptInput" name="auditDept" value=''
                                           style="display: none;display: inline-block;width:278px;" />
                                </div>

                                <div class="form-group " id="identityProveTr" style="display: none">
                                    <label  class="control-label">检&nbsp;&nbsp;索&nbsp;&nbsp;证&nbsp;&nbsp;明：</label>
                                    <div class="form-group" id="identityProve" style="display: inline-block;width:420px">
                                        <input class="form-control" type='file' id="identityProveFile" name="file" style="width: 100%" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label  class="control-label">检索截止时间：</label>
                                    <input class="form-control" type='text' id="planReturnTimeTwo" name="planReturnTimeTwo"
                                           onClick='WdatePicker()' style="display: none;display: inline-block;width:75%;"/>
                                </div>
                                <div class="form-group">
                                    <label  class="control-label" style="vertical-align:top;"> 检&nbsp;&nbsp;索&nbsp;&nbsp;内&nbsp;&nbsp;容：</label>
                                    <textarea rows="1" cols="3" id="auditContent" name="auditContent"
                                              style="width:75%;display: inline-block;"></textarea>
                                </div>
                                <div class="form-group">
                                    <label  class="control-label" style="vertical-align: top;">检&nbsp;&nbsp;索&nbsp;&nbsp;原&nbsp;&nbsp;因：</label>
                                    <input style="width:75%;display: inline-block;" type='text' class="auditReason form-control" id="searchReason" name="searchReason"
                                           value=''  />
                                </div>
                                <div class="form-group" id="modifyPointUserDiv">
                                    <label  class="control-label" style="vertical-align: top;">指定下级领&nbsp;<br/>导审批：</label>
                                    <select class="form-control"  id="modifyUserTable" data-delegateUser="" style="width: 75%;display: inline-block;">
                                    </select>
                                </div>
                            </div>
                        </form>
                    </div>
                    </div>
                    <div class="modal-footer bg-info">
                        <input type="hidden" id="borModifyId" value="">
                        <input type="hidden" id="taskModifyId" value="">
                        <input type="hidden" id="modifyTaskType" value="">
                        <button type="button" class="btn green" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="createDefine"
                            onclick="modifyResult(this);">确认</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 查看文件证明 -->
        <div id="showImg" class="modal fade archivePopUp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog" style="width:900px;height: 700px;text-align: center;">
                <div class="modal-content" style="height: 100%;">
                    <div id="borAttestPdf" style="height:100%;width: 100%">
                        <img id="borAttestImg" style="height:100%;width: 100%;display: none" />
                    </div>
                </div>
            </div>
        </div>
    </section>

</body>
<script>
    //当前代办table
    var $borAuditTable = $("#borAuditTable");
    //自动加载
    $(function () {
        //显示所有的代办检索
        myAuditAction();

        //根据单选结果获取改变时间内容
        $(".radio").find(":radio").change(function () {

            var isRepply = $(this).val();
            console.log(isRepply)
            if (isRepply == 0) {
                $("#modifyTable").hide();
            } else {
                $("#modifyTable").show();
            }
        });

        //查看文件证明图片
        $("#borAttestUrl").click(function () {
            var imgUrl = $("#urlHidden").val();
            if (imgUrl.indexOf("pdf") != -1) {
                $("#borAttestImg").hide();
                var options = {
                    pdfOpenParams: {
                        pagemode: "thumbs",
                        navpanes: '0',
                        /*toolbar: '0',*/ //去掉工具栏,打印,下载等,,,,
                        statusbar: '0',
                        view: 'FitV'
                    }
                };
                //var url="${basePath} /localpdf/大型网站技术架构_核心原理与案例分析_李智慧.pdf";
                var myPDF = PDFObject.embed(imgUrl, "#borAttestPdf", options);
            } else {
                $("#borAttestImg").show();
                $("#borAttestImg").attr({ src: imgUrl, alt: "查看图片" });
            }
            $("#showImg").modal("show");
        })
    })

    /************************************当前代办的流程总览（开始）****************************/
    //显示待办流程
    function myAuditAction() {
        $borAuditTable.bootstrapTable("destroy");
        var url = "${basePath}/pcwindow/getMyAudit";
        var data = { activitiType: "searchActiviti" };
        showSearchAuditTable(url, searchAudit, data);
    }

    function showSearchAuditTable(urla, columns, data) {
        $borAuditTable.bootstrapTable({
            url: urla,
            queryParams: data,//此参数识别当前查询的正在运行的流程为何种流程2：检索流程
            striped: true,
            search: false,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            detailView: false,
            detailFormatter: 'detailFormatter',
            pagination: true,
            pageSize: 50,
            pageList: [50, 100],
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            idField: 'id',
            maintainSelected: true,
            toolbar: '#toolbar',
            columns: columns,
            onLoadSuccess:function(data){
                //无数据隐藏分页
                if(data && data.total == 0){
                    $('.fixed-table-pagination').hide()
                }
            }
        })
        $borAuditTable.bootstrapTable('resetView',{height:setHeight()});
    }
    var searchAudit = [
        { field: 'id', visible: false },//借阅登记表的id
        { field: 'taskId', visible: false },//当前工作流的流程id
        { field: 'registerNum', title: '登记号', sortable: true, align: 'center' },
        { field: 'taskType', title: '申请类型', align: 'center', formatter: 'taskTypeFormat' },
        { field: 'extend1', title: '检索内容', align: 'center' },
        { field: 'borUserName', title: '申请人', align: 'center' },
        { field: 'createTime', title: '申请时间', align: 'center', formatter: 'timeFormat' },
        { field: 'planReturnTime', title: '检索截止时间', align: 'center', formatter: 'planReturnFormat' },
        //                {field: 'taskName', title: '当前节点', align: 'center',formatter:'taskNameFormat'},
        //                {field: 'status', title: '流程状态', align: 'center',formatter:'statusFormat'},
        { field: 'action', title: '操作', align: 'center', formatter: 'actionFormat' }
    ]
    var searchList = [
        { field: 'ck', checkbox: true },
        { field: 'id', visible: false },
        { field: 'registerNum', title: '登记号', sortable: true, align: 'center' },
        { field: 'extend1', title: '检索内容', sortable: true, align: 'center' },
        { field: 'borPurpose', title: '检索原因', sortable: true, align: 'center' },
        {
            field: 'borStatus',
            title: '授权状态',
            sortable: true,
            align: 'center',
            formatter: "accreditStatusFormatter"
        },
        { field: 'planReturnTime', title: '检索到期时间', sortable: true, align: 'center', formatter: "timeFormatter" },
        { field: 'action', title: '操作', align: 'center', formatter: 'authActionFormat' }
    ]
    function actionFormat(value, row, index) {
        return [
            '<shiro:hasPermission name="cms:borAudit:myAudit"><a class="update" href="javascript:;" onclick="auditAction(' + row.id + ',' + row.taskId + ',' + index + ')"  data-toggle="tooltip" title="audit">回复</a></shiro:hasPermission>'
        ].join('');
    }

    //初始化检索操作
    function taskTypeFormat(value, row, index) {
        if (value == "3") {
            return "检索";
        }
    }
    /**
     *    格式化时间(格式YYYY-dd-MM HH:mm:ss)
     */
    function timeFormatter(value, row, index) {
        return formatshortDateTime(value);
    }

    //初始化时间操作
    function timeFormat(value, row, index) {
        if (typeof (value) == "number") {
            return formatDateTime(value);
        } else {
            var time = value.time;
            return formatDateTime(time);
        }
    }
    //授权状态初始化
    function accreditStatusFormatter(value, row, index) {
        if (value == 0) {
            return '<font style="color:#f0692f;">未授权</font>';
        } else if (value == 1) {
            return '<font style="color:darkgreen;">已授权</font>';
        } else {
            return '<font style="color:darkred;">权限已过期</font>';
        }
    }

    //授权按钮初始化
    function authActionFormat(value, row, index) {
        var borStatus = row.borStatus;
        if(borStatus==0){
            return '<a style="color:#01579b;" href="javascript:void(0)" onclick="authAction()" >授权</a>';
        }else{
            return '--';
        }
    }
    //流程状态初始化
    function taskNameFormat(value, row, index) {
        return '<a style="color: blue" href="#" pid="' + row.processId + '" pdid="' + row.processDefinitionId + '" onclick="watchProcessPic(this);" title="点击查看流程图">' + value + '</a>';
    }

    //流程状态初始化
    function statusFormat(value, row, index) {
        return row.suspended ? "已挂起" : "正常" + " V : " + row.actVersion;
    }

    //初始化检索到期时间操作
    function planReturnFormat(value, row, index) {
        if (typeof (value) == "number") {
            return formatshortDateTime(value);
        } else {
            var time = value.time;
            return formatshortDateTime(time);
        }
    }

    function authAction() {
        window.location.href = '${basePath}/pcwindow/searchArcAll';
    }

    //弹出审核内容
    function auditAction(borId, taskId, index) {
        $("#auditUserView").val("");
        var data = $borAuditTable.bootstrapTable('getData')[index];
        //当前节点的英文名称
        var tkey = data.taskDefinitionKey;
        //是否为指定审核人
        var pointUserStatus = false;
        //指定的用户代词为什么
        var pointUser = '';
        $.ajax({
            url: "${basePath}/activiti/common/selectNextTaskUser/" + data.taskId,
            type: "get",
            async: false,
            dataType: "json",
            success: function (data) {
                var code = data.code;
                //当前为指定人选
                if (code == 1) {
                    pointUserStatus = true;
                    // 当前流程中 赋予的代表用户${user }===> user
                    pointUser = data.message;
                } else {
                    if (data.message != null) {
                        Ewin.alert(data.message);
                        return;
                    }
                }
            }
        })

        //调整申请
        if (tkey.indexOf("modifyApply")!=-1) {
            // debugger
            //获取驳回资料
            var AppliInfo = '';
            $.ajax({
                url: BASE_PATH + "/pcwindow/getModifyAppliInfo",
                data: { borId: borId },
                type: "post",
                async: false,
                success: function (result) {
                    AppliInfo = result;
                }
            });
            var taskType = data.taskType;
            $.ajax({
                url: BASE_PATH + "/pcwindow/getOrganization",
                async: false,
                type: "post",
                success: function (organizations) {
                    if (organizations == "0") {
                        //无组织机构进行检索
                        //清空部门数据
                        $("#borDeptTwo").empty();
                        $("#auditDeptTd").find("#borDeptTwo").hide();
                        $("#auditDeptTd").find("#auditDeptInput").show();
                        $("#identityProveTr").show();
                        $("#auditDeptInput").val(data.borDeptDescription);
                    } else {
                        //有组织机构进行检索
                        //清空部门数据
                        $("#borDeptTwo").empty();
                        $("#auditDeptTd").find("#borDeptTwo").show();
                        $("#auditDeptTd").find("#auditDeptInput").hide();
                        $("#identityProveTr").hide();
                        var option = "";
                        $.each(organizations, function (i, items) {
                            option = "<option value=" + items.organizationId + ">" + items.name + "</option>";
                            var $option = $(option);
                            $("#borDeptTwo").append($option);
                        })
                        $("#borDeptTwo").val(data.borDeptId).select2();
                    }
                }
            })
            $("#planReturnTimeTwo").val(formatshortDateTime(data.planReturnTime));
            $("#searchReason").val(data.borPurpose);
            $("#auditContent").text(data.extend1);
            $("#rejectReason").text(AppliInfo.extend1 + " : " + AppliInfo.auditUserView);
            $("#borModifyId").val(borId);
            $("#taskModifyId").val(taskId);
            $("#modifyTaskType").val(data.taskType);
            if (pointUserStatus) {
                $("#modifyUserTable").attr("data-delegateUser", pointUser);
                $("#modifyPointUserDiv").show();
                $.ajax({
                    url: "${basePath}/pcwindow/showAllUser",
                    type: 'get',
                    data: "",
                    dataType: "json",
                    success: function (data) {
                        $('#modifyUserTable').empty();
                        $('#modifyUserTable').select2({
                            placeholder: '请选择下一个审批人',
                            allowClear: true
                        });
                        var allList = data.rows;
                        var option = '';
                        for (var index in allList) {
                            var user = allList[index];
                            option += "<option value='" + user.firstName + "'>" + user.lastName + "</option>";
                        }
                        var $option = $(option);
                        $("#modifyUserTable").append($option);
                    }
                })
            } else {
                $("#modifyPointUserDiv").hide();
                $("#modifyUserTable").attr("data-delegateUser", '');
            }
            $("#modifyApply").modal("show");
        } else {
            //正常审核
            $("#borUserName").text(data.borUserName);

            if (data.borDeptName != null) {
                $("#borDeptName").text(data.borDeptName);
            } else {
                $("#borDeptName").text(data.borDeptDescription);
            }
            //如果没有组织部门id，则显示查看证明的字段
            if (data.borDeptId) {
                $("#borAttestUrlTr").hide();
                $("#urlHidden").val("");
            } else {
                $("#urlHidden").val(data.borAttestUrl);
                $("#borAttestUrlTr").show();
            }
            $("#planReturnTime").text(formatshortDateTime(data.planReturnTime));
            $("#auditDetail").text(data.extend1);
            $("#auditReason").text(data.borPurpose);
            $("#taskType").val(data.taskType);
            $("#borId").val(borId);
            $("#taskId").val(taskId);
            if (pointUserStatus) {
                $.ajax({
                    url: "${basePath}/pcwindow/showAllUser",
                    type: 'get',
                    data: "",
                    dataType: "json",
                    success: function (data) {
                        $('#auditUserTable').empty();
                        $('#auditUserTable').select2({
                            placeholder: '请选择下一个审批人',
                            allowClear: true
                        });
                        var allList = data.rows;
                        var option = '';
                        for (var index in allList) {
                            var user = allList[index];
                            option += "<option value='" + user.firstName + "'>" + user.lastName + "</option>";
                        }
                        var $option = $(option);
                        $("#auditUserTable").append($option);
                    }
                })
                $("#auditUserTable").attr("data-delegateUser", pointUser);
                $("#auditPointUserDiv").show();
            } else {
                $("#auditPointUserDiv").hide();
                $("#auditUserTable").attr("data-delegateUser", '');
            }
            $("#searchAuditModal").modal("show");
        }
    }

    /************************************当前代办的流程总览（结束）****************************/

    /**
     * 查看流程图
     */
    function watchProcessPic(evn) {
        var processId = $(evn).attr("pid");
        var processDefinitionId = $(evn).attr("pdid");
        graphTrace(processId, processDefinitionId);
    }

    /**
     * 审核逻辑
     * @param type
     */
    function borAuditResult(type, evn) {
        $(evn).attr("disabled", true);
        var taskId = $("#taskId").val();
        var borId = $("#borId").val();
        var taskType = $("#taskType").val();
        var auditUserView = $("#auditUserView").val();
        var flag;
        var delegateUser;
        var userName;
        if (type) {
            flag = "true";
            //替代实际人
            delegateUser = $("#auditUserTable").attr("data-delegateUser");
            //判断当前是否为指定审批人表达式
            if (delegateUser != '' || typeof (delegateUser) != "undefined") {
                userName = $("#auditUserTable").val();
            }
        } else {
            flag = "flase";
        }

        $.ajax({
            url: "${basePath}/pcwindow/borAuditResult",
            type: "post",
            data: { taskId: taskId, borId: borId, auditUserView: auditUserView, keys: "pass", values: flag, types: 'B', taskType: taskType, delegateUser: delegateUser, userName: userName },
            dataType: "json",
            success: function (data) {
                if (data.code == 1) {
                    $(evn).attr("disabled", false);
                    $("#searchAuditModal").modal("hide");
                    $borAuditTable.bootstrapTable('refresh');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                Ewin.alert(textStatus);
            }
        })
    }

    /**
     * 修改流程结果(包含重新发起检索流程)
     */
    function modifyResult(evn) {
        $(evn).attr("disabled", true);
        var $evn = $(evn);
        var borModifyId = $("#borModifyId").val();
        var taskModifyId = $("#taskModifyId").val();
        var isApply = $(".radio").find(":checked").val();
        var taskType = $("#modifyTaskType").val();
        var flag = '';
        if (isApply == 0) {
            flag = false;
            $.ajax({
                url: BASE_PATH + "/pcwindow/borAuditResult",
                type: "post",
                data: {
                    taskId: taskModifyId,
                    borId: borModifyId,
                    auditUserView: "取消申请",
                    keys: "reApply",
                    values: flag,
                    types: 'B',
                    taskType: taskType
                },
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        $evn.attr("disabled", false);
                        $("#modifyApply").modal("hide");
                        $borAuditTable.bootstrapTable('refresh');
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Ewin.alert(textStatus);
                }
            })
        } else {
            var delegateUser;
            var userName;
            var flag = true;
            var formData = new FormData();
            formData.append("taskId", taskModifyId);
            formData.append("borId", borModifyId);
            formData.append("keys", "reApply");
            formData.append("values", flag);
            formData.append("types", "B");
            if (!modifyValidator()) {
                $evn.attr("disabled", false);
                return;
            }
            formData.append("borDeptId", typeof ($("#borDeptTwo").find(":selected").val()) == 'undefined' ? '' : $("#borDeptTwo").find(":selected").val());
            formData.append("borDeptDescription", $("#auditDeptInput").val());
            formData.append("planReturnTime", $("#planReturnTimeTwo").val());
            formData.append("extend1", $("#auditContent").val());
            formData.append("borPurpose", $("#searchReason").val());
            formData.append("taskType", taskType);
            //替代实际人
            delegateUser = $("#modifyUserTable").attr("data-delegateUser");
            //判断当前是否为指定审批人表达式
            if (delegateUser != '' || typeof (delegateUser) != "undefined") {
                var userName = $("#modifyUserTable").val();
                formData.append("userName", userName);
            }
            formData.append("delegateUser", delegateUser);
            var returnData = strToDate($("#planReturnTimeTwo").val());
            var nowDate = new Date();
            if (nowDate > returnData) {
                confirmEvent('时间不可小于或等于当前时间');
                $(evn).attr("disabled", false);
                return;
            }

            $.ajax({
                url: BASE_PATH + "/pcwindow/modifySearchAudit",
                method: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 1) {
                        $("#modifyApply").modal("hide");
                        $evn.attr("disabled", false);
                        $borAuditTable.bootstrapTable('refresh');
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    confirmEvent('系统开小差了，请稍后再试!');
                    $evn.attr("disabled", false);
                }
            })
        }
    }

    //修改表单验证
    function modifyValidator() {
        var flag = true;
        //没有组织部门
        var borDept;
        var planReturnTime;
        var searchReason;
        var auditContent;
        var str = "";
        borDept = $("#borDeptTwo").find(":selected").val();
        planReturnTime = $("#planReturnTimeTwo").val();
        searchReason = $("#searchReason").val();
        auditContent = $("#auditContent").val();
        if (borDept == "" && $("#auditDeptInput").val() == '') {
            flag = false;
            str += "组织部门 ";
        }
        if (planReturnTime == null || planReturnTime == "") {
            flag = false;
            str += "检索到期时间 ";
        }
        if (auditContent == null || auditContent == "") {
            str += "检索内容";
        }
        if (searchReason == null || searchReason == "") {
            flag = false;
            str += "检索理由 ";
        }
        if (!flag) {
            confirmEvent(str + "不能为空");
        }
        return flag;
    }

    function allSearchListAction() {
        $borAuditTable.bootstrapTable("destroy");
        var url = "${basePath}/pcwindow/getSearchRegiser";
        showSearchAuditTable(url, searchList);
    }

    /**
     * 表格高度自适应
     * @return
     * winTop 浏览器视口高度
     * header 顶部通栏
     * breadcrumb 面包屑
     * mainFooter 底部
     */
    function setHeight(){
        var winTop = $(window.top).height(),
            header = window.top.document.querySelector('.main-header').offsetHeight,
            breadcrumb =  window.top.document.querySelector('.breadcrumb').offsetHeight,
            mainFooter = window.top.document.querySelector('.main-footer').offsetHeight;
        return winTop-header-breadcrumb-mainFooter-10;
    }
</script>

</html>